' An original BASIC Anywhere Machine program by Charlie Veniot
' Version 2023-01-06 21:13:45
SCREEN _NEWIMAGE(640,640,12)
If GETSESSIONSTORAGEITEM("help_seen") <> "Y" THEN
    _ALERT("START A NEW DRAWING:\nRefresh this web page.\n\nSET THE DRAWING WIDTH-TO-HEIGHT RATIO:\nResize this browser window now (Before pressing the [OK] button)\n\nPAUSE THE DRAWING:\nClick-and-hold the left-mouse-button (or touch-and-hold) anywhere in the drawing area, and then let go to continue\n(or: right-mouse-click, or whatever action, to bring up your browser's context menu; you will then need to click/touch the image area to continue drawing)")
    _DELAY 0.0125
    SETSESSIONSTORAGEITEM("help_seen", "Y")
END IF
TYPE tObject 
   exists%
   x%
   y%
   c%
END TYPE
max% = 166
min% = 30
sx = 663
sy = sx * _windowHeight / _windowWidth
cmax% = 14
DIM g1_object(1 TO max%) AS tObject
DIM c_opt(1 TO cmax%) AS INTEGER
 c_opt(1) = 1: c_opt(2) = 1: c_opt(3) = 1: c_opt(4) = 1: c_opt(5) = 1: c_opt(6) = 1: c_opt(7) = 4: c_opt(8) = 4: c_opt(9) = 4: c_opt(10) = 4: c_opt(11) = 4: c_opt(12) = 15: c_opt(13) = 15: c_opt(14) = 15
FUNCTION DrawingIncomplete%()
    sum_exists = 0
    FOR this_o = 1 TO max%
        sum_exists += g1_object(this_o).exists%
    NEXT
DrawingIncomplete% = sum_exists
END FUNCTION
SCREEN _NEWIMAGE(sx,sy,12)
DO
  WHILE _MOUSEBUTTON : WEND
  FOR i = 1 TO max%
    IF g1_object(i).exists% = TRUE THEN
      IF g1_object(i).x% = g1_object(i).y% THEN
        g1_object(i).x% -= 1
        g1_object(i).y% -= 1
      ELSEIF g1_object(i).x% > g1_object(i).y% THEN
        g1_object(i).y% -= CINT(g1_object(i).y%/g1_object(i).x%)
        g1_object(i).x% -= 1
      ELSE
        g1_object(i).x% -= CINT(g1_object(i).x%/g1_object(i).y%)
        g1_object(i).y% -= 1
      END IF
      IF (g1_object(i).x% <= 0) OR (g1_object(i).y% <= 0) THEN
        g1_object(i).exists% = FALSE
      ELSEIF (g1_object(i).x% >= 0) AND (g1_object(i).y% >= 0) THEN
        PSET (g1_object(i).x%, g1_object(i).y%), g1_object(i).c%
        PSET (sx-1-g1_object(i).x%, g1_object(i).y%), g1_object(i).c%
        PSET (g1_object(i).x%, sy-1-g1_object(i).y%), g1_object(i).c%
        PSET (sx-1-g1_object(i).x%, sy-1-g1_object(i).y%), g1_object(i).c%
      END IF
    END IF
  NEXT i
  IF DrawingIncomplete%() = 0 THEN
    _DELAY 1.75
    xPos = INT(RND * sx)
    yPos = INT(RND * sy)
    line_length = INT(RND * (max%-min%+1)) + min%
    angle = INT(RND * 360)
    i = 1
    PRESET(xPos, yPos)
    DO
      g1_object(i).exists% = TRUE : g1_object(i).x% = xPos : g1_object(i).y% = yPos : g1_object(i).c% = c_opt(INT(RND*cmax%)+1)
      PSET (sx-1-xPos, yPos), g1_object(i).c%
      PSET (xPos, sy-1-yPos), g1_object(i).c%
      PSET (sx-1-xPos, sy-1-yPos), g1_object(i).c%
      PSET (xPos, yPos), g1_object(i).c%
      IF (xPos = sx-1) OR (xPos = 0) OR (yPos = sy-1) OR (yPos = 0) THEN
        bDone = TRUE
      ELSE
        bDone = FALSE
        DRAW "BTA" + angle + "D1"
        xPos = POINT(0) : yPos = POINT(1)
        i = i + 1
      END IF
    LOOP UNTIL (i > (max%)) OR ( bDone = TRUE )
  END IF
  _DELAY 0.001
loop